package com.mytaobao;

import android.content.Context;

import com.baseproject.BaseApplication;
import com.baseproject.BaseProjectAppCofig;
import com.baseproject.datasource.RepositoryComponent;
import com.baseproject.util.AppUtils;
import com.baseproject.util.CrashHandler;
import com.baseproject.util.FileUtil;
import com.baseproject.util.FileUtils;
import com.mytaobao.util.Const;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;


public class TaobaoApplication extends BaseApplication {

    private RepositoryComponent mRepositoryComponent;

    private RefWatcher refWatcher;

    public static RefWatcher getRefWatcher(Context context) {
        TaobaoApplication application = (TaobaoApplication) context.getApplicationContext();
        return application.refWatcher;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        refWatcher = LeakCanary.install(this);
        CrashHandler.getInstance().init(getApplicationContext());
        AppUtils.init(this);

        BaseProjectAppCofig.getInstance(new AppConfig());
    }

    /**
     * 获取上下文
     */
    public static TaobaoApplication getApplication() {
        if (null == application) {
            synchronized (TaobaoApplication.class) {
                if(null == application) {
                    application = new TaobaoApplication();
                }
            }
        }
        return (TaobaoApplication) application;
    }

    @Override
    protected void initApplication() {
        application = this;
    }

    @Override
    protected void mkDir() {
        if (!FileUtils.isFolderExist(Const.APP_ROOT_DIRECTORY)) {
            FileUtil.createDirs(Const.APP_ROOT_DIRECTORY);
        }
    }
}
